<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="关联分润配置" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="configId">
<!--
              <a-input v-model="model.configId" placeholder="请输入关联分润配置"  ></a-input>
-->

              <a-select v-model="model.configId" placeholder="请选择配置">
                <a-select-option v-for="item in profitList" :key="item.id" :value="item.id">
                  {{ item.name }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="参与方类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="roleType">
              <a-select v-model="model.roleType" placeholder="请输入参与方类型">
                <a-select-option :value="1">投资人</a-select-option>
                <a-select-option :value="2">场地方</a-select-option>
                <a-select-option :value="3">管理方</a-select-option>
                <a-select-option :value="4">平台方</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="计算方式（1-固定 2-比例）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="calculationType">
<!--              <a-input v-model="model.calculationType" placeholder="请输入计算方式（1-固定 2-比例）"  ></a-input>-->
              <a-select v-model="model.calculationType" placeholder="请输入参与方类型">
                <a-select-option :value="1">固定</a-select-option>
                <a-select-option :value="2">比例</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="适用条件（如：订单金额>1000）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="profitCondition">
              <a-input v-model="model.profitCondition" placeholder="请输入适用条件（如：订单金额>1000）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="计算优先级（数字越小越优先）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="priority">
              <a-input-number v-model="model.priority" placeholder="请输入计算优先级（数字越小越优先）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ProfitParticipantForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        profitList:[],
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/rental/profitParticipant/add",
          edit: "/rental/profitParticipant/edit",
          queryById: "/rental/profitParticipant/queryById",
          profitList: "/rental/profitSharingConfig/list",
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
      this.gettypelist();
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      gettypelist(){
        let that=this;
        let data={pageSize:100,pageNo:1}
        getAction(this.url.profitList,data).then((res)=>{
          let datass=[]
          res.result.records.forEach(itme=>{
            datass.push({name:itme.strategyName,id:itme.id})
          })
          this.profitList=datass;
          console.log(datass,"gettypelist")
        }).finally(() => {

        })
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>